﻿using System;
using System.Collections.ObjectModel;
using System.Xml.Serialization;
using Startup.Base.Delegates;
using Startup.Shell.Domain.FunctionalityContracts;

namespace Startup.Shell.ModelDesignerPreview
{
	[XmlInclude(typeof(IDesignerPreview))]
	[XmlInclude(typeof(WindowDesignerPreview))]
	[XmlInclude(typeof(LeftPanelPreview))]
	[XmlInclude(typeof(TopPanelPreview))]
	[XmlInclude(typeof(RendererPanelPreview))]
	[XmlInclude(typeof(CommandsPanelPreview))]
	[XmlInclude(typeof(ToolbarPanelPreview))]
	public class PreviewContainer
	{
		public event UnparameterizedDelegate PreviewChanged;
        
		private IDesignerPreview _preview;
		private Guid _dataContextPropertyId;

		public ObservableCollection<CommandContractBase> Commands
		{
			get
			{
				if (Preview == null)
					return null;

				if (Preview is CommandsPanelPreview)
					return ((CommandsPanelPreview) Preview).Commands;

				return null;
			}
		}

		public bool ShowCommands
		{
			get { return Commands != null; }
		}

		public bool ShowPreview
		{
			get { return !ShowCommands; }
		}

		public IDesignerPreview Preview
		{
			get { return _preview; }
			set
			{
				if (_preview == value)
					return;

				_preview = value;

				if (PreviewChanged != null)
					PreviewChanged();
			}
		}

		public Guid DataContextPropertyId
		{
			get { return _dataContextPropertyId; }
			set
			{
				if (_dataContextPropertyId == value)
					return;

				_dataContextPropertyId = value;

				if (PreviewChanged != null)
					PreviewChanged();
			}
		}

		public string GetCode()
		{
			throw new Exception();
		}
	}
}
